package com.jj.controller;

import com.jj.dto.ProductTypeWithProductsDTO;
import com.jj.entity.Products;
import com.jj.service.ProductService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @RequestMapping("/selectById")
    public Products selectById(@Param("productId") Integer productId) {
        return productService.selectById(productId);
    }

    @RequestMapping("/selectAllTypesWithProducts")
    public List<ProductTypeWithProductsDTO> selectAllTypesWithProducts() {
        return productService.selectAllTypesWithProducts();
    }

    @RequestMapping("/insertProduct")
    public int insertProduct(Products product) {
        return productService.insertProduct(product);
    }

    @RequestMapping("/updateProduct")
    public int updateProduct(Products product) {
        return productService.updateProduct(product);
    }

    @RequestMapping("/deleteById")
    public int deleteById(@Param("productId") Integer productId) {
        return productService.deleteById(productId);
    }

    @RequestMapping("/selectAllProducts")
    public List<ProductTypeWithProductsDTO> selectAllProducts(@Param("productName") String productName) {
        return productService.selectAllProducts(productName);
    }

}
